/*
 * Copyright Aristool AG Switzerland
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 */

package org.opprua.dss.application;

import org.opprua.tidy.util.XReader;
import org.w3c.dom.Element;

/**
 * TODO: add Java doc
 * 
 * Prepared for first commit: 23.02.2007
 * 
 * @author Lin Li
 */
public class DAppReader extends XReader {

  private DComponent[] components;
  private DSelect[] selects;
  private DEntry[] entries;
  private DDataPoint[] dataPoints;
  private DProvider[] providers;

  public DAppReader() {
  }

  @Override
  public void read(Element e) {
    components = collect(e, "component", DComponent.class);
    selects = collect(e, "select", DSelect.class);
    entries = collect(e, "entry", DEntry.class);
    dataPoints = collect(e, "dataPoint", DDataPoint.class);
    providers = collect(e, "provider", DProvider.class);
  }
  
  public String getGuard() {
    return getAttribute("guard");
  }
  
  public DComponent[] getComponents() {
    return components;
  }

  public DEntry[] getEntries() {
    return entries;
  }

  public DProvider[] getProviders() {
    return providers;
  }

  public DSelect[] getSelects() {
    return selects;
  }

  public DDataPoint[] getDataPoints() {
    return dataPoints;
  }

  @SuppressWarnings("unchecked")
  public <T extends XReader> T[] getEls(Class<T> c) {
    if (c.equals(DComponent.class)) return (T[]) components;
    if (c.equals(DEntry.class)) return (T[]) entries;
    if (c.equals(DProvider.class)) return (T[]) providers;
    if (c.equals(DSelect.class)) return (T[]) selects;
    if (c.equals(DDataPoint.class)) return (T[]) dataPoints;
    return null;
  }
}
